package com.vincent.sciinfo.controller;

import com.vincent.sciinfo.pojo.Source;
import com.vincent.sciinfo.pojo.TSMResult;
import com.vincent.sciinfo.service.SourceService;
import com.vincent.sciinfo.utils.StatusCode;
import com.vincent.sciinfo.utils.StatusMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;

@RestController
@RequestMapping("/source")
public class SourceController {

    @Autowired
    private SourceService sourceServer;

    @RequestMapping("/saveFilePath")
    public int saveFilePath(@RequestParam String filePathSaved, @RequestParam String fileName) {
        return sourceServer.saveFilePath(filePathSaved, fileName);
    }

    //查询是否存在论文 存在论文文件信息的 才给予下载
    @RequestMapping(value = "/isExistsFilename")
    public TSMResult isExistsFilename(@RequestParam("paperName") String paperName) throws UnsupportedEncodingException {
        Source source = sourceServer.isExistsPaperFile(paperName);
        Boolean isExists = (source == null) ? false : true;
        return new TSMResult(StatusCode.SUCCESS, StatusMessage.SUCCESS, isExists);
    }


    @RequestMapping("/isExistsPaperFile")
    public Source isExistsPaperFile(@RequestParam String paperOriginalName){
        return sourceServer.isExistsPaperFile(paperOriginalName);
    }

}
